package cc.rengu.redp.bizimpl.upmp.service.impl;

import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.bizimpl.upmp.dao.UserCommonFunMapper;
import cc.rengu.redp.bizimpl.upmp.domain.UserCommonFun;
import cc.rengu.redp.bizimpl.upmp.vo.UserCommonFunVO;
import cc.rengu.redp.bizimpl.upmp.service.IUserCommonFunService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author guohaocong
 */
@Service
@Slf4j
public class UserCommonFunServiceImpl extends ServiceImpl<UserCommonFunMapper, UserCommonFun> implements IUserCommonFunService {


    @Override
    public List<UserCommonFunVO> findCommonMenus(String instId, String userId) throws RedpException {
        List<UserCommonFunVO> commMenusVO = null;
        try {
            commMenusVO = this.baseMapper.getCommMenus(instId, userId);
            return commMenusVO;
//            if (commMenus != null) {
//                return commMenus;
//            } else {
//                return null;
//            }
        } catch (Exception e) {
            String message = e.getMessage();
            log.info(message);
            throw  new RedpException(message);
        }


    }

    @Override
    public void deleteMenuById(String id) {
        LambdaQueryWrapper<UserCommonFun> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserCommonFun::getMenuId,id);
        this.baseMapper.delete(lambdaQueryWrapper);
    }
}
